package cn.zyx.user.controller;

import cn.zyx.basic.exception.BusinessException;
import cn.zyx.basic.util.AjaxResult;
import cn.zyx.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 短信验证接口 -- 只能传入一个手机号 -- 前端传phone和type过来，type做不同的业务区分
     * @param param
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> param){
        try {
            verifyCodeService.sendSmsCode(param);
            return AjaxResult.me();
        } catch (BusinessException e) {
            return AjaxResult.me().setMessage("发送失败!"+e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙,请稍等重试!");
        }
    }
}
